// 定时任务封装
export const timeoutTask = (task, time) => {
  const tmpTimeout = setTimeout(() => {
    task();
    clearTimeout(tmpTimeout);
  }, time);
};

// 菜单拷贝(深度拷贝)
export const deepCopyMenus = (menus) => {
  const target = [];
  const menusLen = menus.length;
  for (let i = 0; i < menusLen; i += 1) {
    target[i] = {
      id: menus[i].id,
      index: menus[i].index,
      parentId: menus[i].parentId,
      name: menus[i].name,
      link: menus[i].link,
      icon: menus[i].icon,
      children: menus[i].children,
      hide: menus[i].hide,
    };
  }
  return target;
};

// 判断是否为数字
export const isNumber = (val) => {
  const regPos = /^\d+(\.\d+)?$/; // 非负浮点数
  const regNeg = /^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$/; // 负浮点数
  if (regPos.test(val) || regNeg.test(val)) {
    return true;
  }
  return false;
};
